package com.sg.business.management.editor.option;

import java.util.ArrayList;
import java.util.List;

import com.sg.business.model.ProjectTemplate;
import com.sg.business.model.WorkDefinition;
import com.sg.widgets.commons.options.IFieldOptionProvider;
import com.sg.widgets.registry.config.Option;

public class ProjectTemplateStepOption implements IFieldOptionProvider {

	@Override
	public Option getOption(Object input, Object data, String key, Object value) {
		List<Option> options = new ArrayList<Option>();
		options.add(new Option("", "", null, null));
		if (data instanceof WorkDefinition) {
			WorkDefinition workDef = (WorkDefinition) data;
			if (workDef.isProjectWork()) {
				ProjectTemplate projectTemplate = workDef.getProjectTemplate();
				List<?> projectStepList = projectTemplate.getProjectStep();
				if (projectStepList != null && projectStepList.size() > 0) {
					for (Object po : projectStepList) {
						options.add(new Option(po.toString(), po.toString(), po
								.toString(), null));
					}
				}
			}
		}
		Option result = new Option("projectstep", "projectstep", "projectstep",
				options.toArray(new Option[] {}));
		return result;
	}
}
